// 拼接瓦片地址
export const getGaoDeTileUrl = (x, y, z) => {
  let domainIndexList = [1, 2, 3, 4];
  let domainIndex =
    domainIndexList[Math.floor(Math.random() * domainIndexList.length)];
  return `https://webrd01.is.autonavi.com/appmaptile?x=${x}&y=${y}&z=${z}&lang=zh_cn&size=1&scale=1&style=8`;
};

export const XYZ = (url, x, y, z) => {
  return url.replace(/{x}/g, x).replace(/{y}/g, y).replace(/{z}/g, z);
};

export const getArcgisUrl = (x, y, z) => {
  return `http://192.168.0.25:6163/igs/rest/mrms/tile/ZCQC5300002021GYX/${z}/${y}/${x}`;
};

export const getWMSUrl = ({ url, parameters }) => {
  return url + "/export" + convertParams(parameters);
};


export const WMSXYZ = (url, parameters = {}) => {
  const params = {
    service: "WMS",
    request: "GetMap",
    layers: "",
    styles: "",
    format: "image/jpeg",
    transparent: "false",
    version: "1.1.1",
    width: "256",
    height: "256",
    srs: "EPSG:4326",
  };
  const obj = {
    ...params,
    ...parameters,
  };
  return url + convertParams(obj);
};

function convertParams(obj) {
  let result = "";
  let item;
  for (item in obj) {
    if (obj[item] && String(obj[item])) {
      result += `&${item}=${obj[item]}`;
    }
  }
  if (result) {
    result = "?" + result.slice(1);
  }
  return result;
}

// getWMSUrl({
//   url: "http://localhost:6080/arcgis/rest/services/newhaha/haha/MapServer",
//   parameters: {
//     dpi:96,
//     transparent: true,
//     format: "png8",
//     imageSR: 4490,
//     f: 'image',
//     bboxSR: 4490,
//     bbox: '99.32962441262003%2C24.87441823550179%2C100.77248192745151%2C26.402765494259196',
//     size: '827%2C876'
//   },
// });
